package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.protection.common.Result;
import com.yqg.protection.entity.HistoryQg;
import com.yqg.protection.mapper.HistoryQgMapper;
import com.yqg.protection.service.IHistoryQgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * HistoryQgController 前端控制器
 * @author zxf
 * @since 2025-08-29
 */
@RestController
@RequestMapping("/history-qg")
public class HistoryQgController {

    @Resource
    private IHistoryQgService historyQgService;

    @Resource
    private HistoryQgMapper historyQgMapper;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody HistoryQg historyQg) {
        return Result.success(historyQgService.saveOrUpdate(historyQg));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        HistoryQg historyQg =historyQgService.getById(id);
        return Result.success(historyQgService.saveOrUpdate(historyQg));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<HistoryQg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<HistoryQg> list=  historyQgService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(historyQgService.getById(id));
    }
    /**
     *  分页查询
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           Long equipmentInputStoreId,
                           String startTime,
                           String endTime) {
        pageNum = pageNum * pageSize - pageSize;
        List<HistoryQg> historyQgs = historyQgMapper.findPage(pageNum, pageSize, equipmentInputStoreId, startTime, endTime);
        Long count = historyQgMapper.findPageCount(equipmentInputStoreId, startTime, endTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("record", historyQgs);
        map.put("total", count);
        return Result.success(map);
    }

}

